package com.maint.m

import android.media.AudioFormat
import android.media.AudioManager
import android.media.AudioTrack
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.maint.m.databinding.ActivitySendmessageBinding
import com.rokid.security.phone.sdk.api.PSecuritySDK
import com.rokid.security.phone.sdk.api.msg.listener.FileReceiveListener
import com.rokid.security.phone.sdk.api.msg.listener.IMessageListener
import com.rokid.security.phone.sdk.api.track.bean.FaceModel
import com.rokid.security.phone.sdk.api.track.bean.LPRModel
import com.rokid.security.phone.sdk.api.track.listener.ITrackListener
import com.rokid.security.sdk.base.common.notifacation.NotificationMessage
import java.io.File
import java.nio.ByteBuffer

class SendMessageActivity : AppCompatActivity() {
    var sendConnect = false
    private val TAG = "SendMessageActivity::"
    private lateinit var binding: ActivitySendmessageBinding
    private val fileReceiveListener = object : FileReceiveListener {
        override fun onStart() {
            Log.e(TAG,"onStart: 对方开始接收文件")
        }
        override fun onProgressChanged(progress: Float) {
            Log.e(TAG,"onProgressChanged: 对方接收文件的进度 $progress")

        }
        override fun onComplete(filePath: String) {

            Log.e(TAG," onComplete: 对方接收文件完成")
        }
        override fun onFail() {

            Log.e(TAG," onFail: 对方接收文件失败")

        }
        override fun onCancel() {
            Log.e(TAG,"onCancel: 取消了发送文件,对方停止接收文件")
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e(TAG, "初始化")
        binding = ActivitySendmessageBinding.inflate(layoutInflater)
        setContentView(binding.root)

        //wifi模式发送文本
        binding.wfSendTextBtn.setOnClickListener {
            PSecuritySDK.getMessageService()?.sendTextMessageByP2P("测试的消息")
        }
        //wifi模式发送数据流
        binding.wfSendAudioBtn.setOnClickListener {
//            PSecuritySDK.getMessageService()?.sendAudioStreamDataByP2P("")
            val fileToSend1 = File(getExternalFilesDir(null), "BT_1754971132308.png")
            val fileToSend2 = File(getExternalFilesDir(null), "BT_1754979904460.png")
            if (sendConnect){
                sendConnect=false
                PSecuritySDK.getMessageService()?.getBtFileOperater()?.sendFile("aaaa",fileToSend1,fileReceiveListener){}
            }else{
                sendConnect=true
                PSecuritySDK.getMessageService()?.getBtFileOperater()?.sendFile("bbbb",fileToSend2,fileReceiveListener){

                }
            }


        }
        binding.btSendTextBtn.setOnClickListener {
            Log.e(TAG,"蓝牙文本")
            PSecuritySDK.getMessageService()?.sendTextMessageByClassicBT("蓝牙消息测试")
        }
        binding.btSendAudioBtn.setOnClickListener {
            Log.e(TAG,"消息通知")
                         val messageBean = NotificationMessage(packageName, "测试", "测试111", "测试消息222", 2000)
                PSecuritySDK.getAbsNotificationService()?.sendNotification(messageBean)
        }
//        binding.btSendAudioBtn.setOnClickListener {
////            PSecuritySDK.getMessageService()?.getBtFileOperater().sendFile()
//        }
        PSecuritySDK.getMessageService()?.getBtFileOperater()?.addFileReceiveListener(fileReceiveListener)
    }




override fun onDestroy() {
    super.onDestroy()

}

}

